<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>vue-router</title>
  </head>
  <body>
    <div id="app">
      <!-- 3创建路由标签 -->
      <!-- router-link会被解析为 ----a
      to会被解析为 ----href -->
      <router-link to="/login">登录</router-link>
      <router-link to="/regiest">注册</router-link>

      <!-- 4创建占位符，填充位 -->
      <!-- 当路由改变时填充到此标签 -->
      <router-view></router-view>
    </div>

    <!-- 1引入VUe  -->
    <!-- 2再引入roter -->
    <script src="../node_modules/vue/dist/vue.js"></script>
    <script src="../node_modules/vue-router/dist/vue-router.js"></script>
    <script>
      // 5创建路由组件
      const login = {
        template: `
        <div>
          <h1>login</h1>
          <h1>login</h1>
        </div>
          `,
      }
      const regiest = {
        template: `
        <div>
          <h1>regiest</h1>
          <h1>login</h1>
        </div>
          `,
      }
      // 6创建路由规则
      const routers = new VueRouter({
        routes: [
          { path: '/', redirect: '/regiest' }, //路由重定向使用redirect
          { path: '/login', component: login },
          { path: '/regiest', component: regiest },
        ],
      })
      const vm = new Vue({
        el: '#app',
        data: {},
        router: routers,
      })
    </script>
  </body>
</html>
